package com.lphj.datainterface.handle;

import com.lphj.datainterface.component.Config.ReadOtherConfig;
import com.lphj.datainterface.entity.TGoods;
import com.lphj.datainterface.entity.TStoreGoodsVendor;
import com.lphj.datainterface.service.TStoreGoodsVendorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class TStoreGoodsVendorHandle {

    @Autowired
    ReadOtherConfig readOtherConfig;

    @Autowired
    TStoreGoodsVendorService tStoreGoodsVendorService;

    /**
     * 分公司商品供应商表
     * @param tGoods
     * @return
     */
    @Transactional
    public int addTStoreGoodsVendor(TGoods tGoods) {
        //清空tStoreGoodsVendor
        tStoreGoodsVendorService.delTStoreGoodsVendor();
        int count = 0;
        if(tGoods != null) {
            TStoreGoodsVendor tStoreGoodsVendor = new TStoreGoodsVendor();
            tStoreGoodsVendor.setsStoreNO(readOtherConfig.getStoreNO());
            tStoreGoodsVendor.setnGoodsID(tGoods.getGoodsID());
            tStoreGoodsVendor.setnVendorID(tGoods.getMainVendorID());
            tStoreGoodsVendor.setnBuyPrice(tGoods.getBuyPrice());
            tStoreGoodsVendor.setnRatio(tGoods.getRatio());
            tStoreGoodsVendor.setnGiftBase(tGoods.getGiftBase());
            tStoreGoodsVendor.setnGiftGoodsID(tGoods.getGiftGoodsID());
            tStoreGoodsVendor.setnGiftQty(tGoods.getGiftQty());
            tStoreGoodsVendor.setsBuyTaxID(tGoods.getBuyTaxID());
            tStoreGoodsVendor.setsBuyTax(tGoods.getBuyTax());
            tStoreGoodsVendor.setnBuyTaxPct(tGoods.getBuyTaxPct());
            tStoreGoodsVendor.setnCaseUnits(tGoods.getCaseUnits());
            tStoreGoodsVendor.setnStatus(tGoods.getStatus());
            tStoreGoodsVendor.setnNormalBuyPrice(tGoods.getBuyPrice());
            tStoreGoodsVendor.setnNormalRatio(0);
            tStoreGoodsVendor.setsPRSTypeID(null);
            tStoreGoodsVendor.setsPromoNO(null);
            tStoreGoodsVendor.setnTag(134);
            tStoreGoodsVendor.setsCreateUser(tGoods.getCreateUser());
            tStoreGoodsVendor.setdCreateDate(tGoods.getCreateDate());
            tStoreGoodsVendor.setsChangeUser(tGoods.getChangeUser());
            tStoreGoodsVendor.setdChangeDate(tGoods.getChangeDate());
            tStoreGoodsVendor.setsConfirmUser(tGoods.getConfirmUser());
            tStoreGoodsVendor.setdConfirmDate(tGoods.getConfirmDate());
            tStoreGoodsVendor.setdLastUpdateTime(tGoods.getLastUpdateTime());
            tStoreGoodsVendor.setdEnterDate(tGoods.getEnterDate());
            tStoreGoodsVendor.setnMinOrderQty(tGoods.getMinOrderQty());
            count += tStoreGoodsVendorService.addTStoreGoodsVendor(tStoreGoodsVendor);
        }
        return count;
    }
}
